﻿using System;
using System.Xml;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.Extensions;
using Ro.AssistFunction.OutputManage;
using Ro.Common.RoArgs;
using Ro.Common.RoInterface.RoWebAction;
using Ro.Common.RoInterface.UserType;

namespace Ro.DriverEvent.WebAction
{
    public class WebScroll : IWebScrollFunc
    {
        /// <summary>
        /// 上滑
        /// </summary>
        /// <param name="sigNode">上滑</param>
        /// <returns>返回是否完成</returns>
        public WebActionResult Up(XmlNode sigNode)
        {
            //返回值
            WebActionResult back;
            try
            {
                //向上滚动
                RoTestObject.WebTestObject.ExecuteJavaScript<IJavaScriptExecutor>("window.scrollTo(0,0)");
                back = BackActionResult.BackWebResult(true, "未使用", "没有附加信息"); //结果
            }
            // 抛出异常

            catch (Exception e)
            {
                back = BackActionResult.BackWebResult(false, "未使用", "Scroll操作Up遭遇System异常"); //结果
                ExceptionOutPut.SystemExceptionOut("Up", e);
            }
            return back;
        }

        /// <summary>
        /// 下拉
        /// </summary>
        /// <param name="sigNode">下拉</param>
        /// <returns>返回是否完成</returns>
        public WebActionResult Down(XmlNode sigNode)
        {
            //返回值
            WebActionResult back;
            try
            {
                //向下滚动
                RoTestObject.WebTestObject.ExecuteJavaScript<IJavaScriptExecutor>("window.scrollTo(0,document.body.scrollHeight");
                back = BackActionResult.BackWebResult(true, "未使用", "没有附加信息"); //结果
            }
            // 抛出异常

            catch (Exception e)
            {
                back = BackActionResult.BackWebResult(false, "未使用", "Scroll操作Down遭遇System异常"); //结果
                ExceptionOutPut.SystemExceptionOut("Down", e);
            }
            return back;
        }
    }
}